package com.tencent.miniproject.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tencent.miniproject.R;
import com.tencent.miniproject.base.BaseRecyclerViewAdapter;
import com.tencent.miniproject.been.DetailComment;
import com.tencent.miniproject.utils.DateUtil;

import butterknife.BindView;
import de.hdodenhof.circleimageview.CircleImageView;


public class DetailCommentsAdapter extends BaseRecyclerViewAdapter<DetailComment> {
    private Context mContext;

    public DetailCommentsAdapter(Context context) {
        mContext = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_detail_comment, parent, false);
        return new DetailCommentHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ((DetailCommentHolder)holder).bindView(mDataList.get(position));
    }


    class DetailCommentHolder extends BaseRvHolder{
        @BindView(R.id.civ_user_img)
        CircleImageView mCivUserImg;
        @BindView(R.id.tv_name)
        TextView mTvName;
        @BindView(R.id.tv_time)
        TextView mTvTime;
        @BindView(R.id.tv_content)
        TextView mTvContent;

        public DetailCommentHolder(View itemView) {
            super(itemView);
        }

        @Override
        protected void bindView(DetailComment detailComment) {
            Glide.with(mContext)
                    .load(detailComment.getHeadUrl())
                    .into(mCivUserImg);
            mTvName.setText(detailComment.getUsername());
            mTvTime.setText(DateUtil.dateFormatDay(detailComment.getTime()));
            mTvContent.setText(detailComment.getContent());
        }
    }
}
